const { DataTypes } = require('sequelize')

module.exports = (sequelize) => {
  const TableAction = sequelize.define('TableAction', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    action_id: {
      type: DataTypes.STRING(50),
      allowNull: false,
      unique: true,
      comment: '操作唯一标识'
    },
    name: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '操作名称'
    },
    description: {
      type: DataTypes.TEXT,
      comment: '操作描述'
    },
    icon: {
      type: DataTypes.STRING(100),
      comment: '图标'
    },
    color: {
      type: DataTypes.STRING(50),
      comment: '颜色'
    },
    permission: {
      type: DataTypes.STRING(100),
      comment: '所需权限'
    },
    confirm_required: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
      comment: '是否需要确认'
    },
    confirm_message: {
      type: DataTypes.TEXT,
      comment: '确认消息'
    },
    api_endpoint: {
      type: DataTypes.STRING(200),
      comment: 'API接口'
    },
    http_method: {
      type: DataTypes.ENUM('GET', 'POST', 'PUT', 'DELETE'),
      defaultValue: 'POST',
      comment: 'HTTP方法'
    },
    status: {
      type: DataTypes.ENUM('active', 'inactive'),
      defaultValue: 'active',
      comment: '状态'
    },
    created_by: {
      type: DataTypes.INTEGER,
      comment: '创建者ID'
    }
  }, {
    tableName: 'table_actions',
    comment: '动态表格操作配置表'
  })

  return TableAction
}